FROM rust:1.72.0-slim-buster

WORKDIR /app

COPY . .

RUN mkdir -p $HOME/.cargo && \
    echo "[source.crates-io]" > $HOME/.cargo/config && \
    echo "replace-with = \"tuna\"" >> $HOME/.cargo/config && \
    echo "[source.tuna]" >> $HOME/.cargo/config && \
    echo "registry = \"sparse+https://mirrors.tuna.tsinghua.edu.cn/crates.io-index/\"" >> $HOME/.cargo/config

RUN rustup target add x86_64-unknown-linux-musl

ENV CC_x86_64_unknown_linux_musl=x86_64-linux-musl-gcc

RUN cargo build --release